package controllers.caterinaController.controllers;

import controllers.Checks;
import controllers.dbWrapper.UserWrapper;
import person.Customer;
import person.Employee;
import person.User;

public class RegistrationManager {
	
	public static void register(User user, String userName, String password) throws Exception{
		Checks.checkUser(userName, password,false);
		if(user instanceof Customer){
			Checks.checkCustomer((Customer)user);
			UserWrapper.insertUserCustomer(userName, password, (Customer) user, true);
			MailManager.sendRegistrationConfirmation(user, userName, password);
		} else {
			UserWrapper.insertUserEmployee(userName, password, (Employee)user, true);
		}
	}
	
	public static void deleteUser(User user) throws Exception{
		UserWrapper.deleteUser(true, user);
	}
	
	public static void modifyUserPassword(String password) throws Exception{
		User current= LoginManager.getCurrentLogged();
		String userName=UserWrapper.getuserName(current,false);
		Checks.checkUser(userName, password,false);
		UserWrapper.modifyPassword(userName, password, true);
	}
}
